//
//  ViewController.m
//  OCAnimation
//
//  Created by zhouLiHuan on 2017/2/17.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

#import "ViewController.h"
#import "AnimMode.h"
#import "BaseAnimViewController.h"
#import "DrawLineViewController.h"
#import "FireViewController.h"
#import "KeyFrameViewController.h"
#import "SpringViewController.h"
#import "TransitionViewController.h"
#import "WaterWaveViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic,strong)NSArray *dataDictArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataDictArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    AnimMode *animModel = self.dataArr[indexPath.row];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.textLabel.text = animModel.title;
        cell.backgroundColor = [UIColor grayColor];
        cell.textLabel.textColor = [UIColor blackColor];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AnimMode *model = self.dataArr[indexPath.row];
    
    if ([model.className isEqualToString:@"BaseAnimViewController"]) {
        
        [self.navigationController pushViewController:[BaseAnimViewController new] animated:YES];
    }else if ([model.className isEqualToString:@"DrawLineViewController"]){
        [self.navigationController pushViewController:[DrawLineViewController new] animated:YES];
        
    }else if ([model.className isEqualToString:@"FireViewController"]){
        [self.navigationController pushViewController:[FireViewController new] animated:YES];
        
    }else if ([model.className isEqualToString:@"KeyFrameViewController"]){
        [self.navigationController pushViewController:[KeyFrameViewController new] animated:YES];
        
    }else if ([model.className isEqualToString:@"SpringViewController"]){
        [self.navigationController pushViewController:[SpringViewController new] animated:YES];
        
    }else if ([model.className isEqualToString:@"TransitionViewController"]){
        [self.navigationController pushViewController:[TransitionViewController new] animated:YES];
        
    }else{

        [self.navigationController pushViewController:[WaterWaveViewController new] animated:YES];
    }
}


#pragma mark - 懒加载
- (UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] init];
        _tableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

- (NSArray *)dataDictArr{
    if (_dataDictArr == nil) {
        
        _dataDictArr = @[@{@"className":@"BaseAnimViewController",@"title":@"ABasicAnimation基础动画"},
                         @{@"className":@"DrawLineViewController",@"title":@"画线动画、线条递增、递减动画"},
                         @{@"className":@"FireViewController",@"title":@"粒子动画-火苗效果"},
                         @{@"className":@"KeyFrameViewController",@"title":@"CAKeyframeAnimation基础动画"},
                         @{@"className":@"SpringViewController",@"title":@"基本动画"},
                         @{@"className":@"TransitionViewController",@"title":@"CATransition转场动画"},
                         @{@"className":@"WaterWaveViewController",@"title":@"水波纹效果"}
                         ];
    }
    return _dataDictArr;
}


- (NSMutableArray *)dataArr{
    if (_dataArr == nil) {
        _dataArr = [[NSMutableArray alloc] init];
        for (NSDictionary *dict in self.dataDictArr) {
            AnimMode *model = [AnimMode animWithDict:dict];
            [_dataArr addObject:model];
        }
    }
    return _dataArr;
}
@end
